package ma.sqli.vehicles;

import java.text.DecimalFormat;

public class Vehicle {

	protected double consomptionRate;
	protected String vehicleId;
	protected int numberOfDoors;
	protected String fuelType;
	protected Doors doors ;
	
	public Vehicle(String vehicle_id, int numberOfDoors, double consomptionRate) 
	{
		this.vehicleId = vehicle_id;
		this.numberOfDoors = numberOfDoors;
		this.consomptionRate = consomptionRate;
		doors = new Doors();
	}

	
	public String getVehicleReport( String closedDoors , String distance )
	{	
		String consumptionReport = getConsumptionReport(distance);
		String doorsReport = doors.getClosedDoorsReport(closedDoors, this.numberOfDoors, consumptionReport) ;
		
		return doorsReport ;
	}
	
	protected String getConsumptionReport(String distance) 
	{
		String[] distanceWithoutKmUnit = distance.split(" ");
		double parsedDistance = Double.parseDouble(distanceWithoutKmUnit[0]);
		double fuelConsumption = parsedDistance * consomptionRate;
		
		DecimalFormat distanceDecimalFormat = new DecimalFormat("#.00"); 
		String consumptionReport = "The " + vehicleId + " will consume " + distanceDecimalFormat.format(fuelConsumption) + " L";
		return consumptionReport;
	}
	
	
	
	
}
